<?php

namespace models\DAO;

use models\Exception\DAO\ModelDriverException;
use models\Exception\DAO\ModelException;
use models\Exception\DAO\ModelReflectionException;
use models\Exception\DAO\ModelSqlException;


/**
 * @SWG\Swagger(
 *     @SWG\Definition(
 *          type="object",
 *          definition="systemSingleData",
 *          required={"errno", "errmsg", "data"},
 *          @SWG\Property(property="errno", type="integer", format="int32", description="编码"),
 *          @SWG\Property(property="errmsg", type="string", format="string", description="错误提示信息"),
 *          @SWG\Property(property="result", type="object", ref="#/definitions/systemSingleObj")
 *     ),
 *     @SWG\Definition(
 *          type="object",
 *          definition="systemSingleObj",
 *          @SWG\Property(property="data", type="object", ref="#/definitions/systemSingle")
 *     ),
 *     @SWG\Definition(
 *          type="object",
 *          definition="systemListData",
 *          required={"errno", "errmsg", "result"},
 *          @SWG\Property(property="errno", type="integer", format="int32", description="编码"),
 *          @SWG\Property(property="errmsg", type="string", format="string", description="错误提示信息"),
 *          @SWG\Property(property="result", ref="#/definitions/systemListObj"),
 *     ),
 *     @SWG\Definition(
 *          type="object",
 *          definition="systemListObj",
 *          @SWG\Property(property="data", type="object", ref="#/definitions/systemData"),
 *          @SWG\Property(property="meta", ref="#/definitions/meta")
 *     ),
 *     @SWG\Definition(
 *          type="array",
 *          definition="systemData",
 *          @SWG\Items(
 *              title="data", ref="#/definitions/systemSingle"
 *          )
 *     ),
 *     @SWG\Definition(
 *          type="object",
 *          definition="systemSingle",
 *          @SWG\Property(property="id", type="integer", format="int32",  description="主键"),
 *          @SWG\Property(property="default_post_fee", type="string", format="string",  description="基础运费(单位:元,默认:6)"),
 *          @SWG\Property(property="exchange_rate", type="string", format="string",  description="兑换商品所需的积分与商品价格的比例(单位%,默认1000%)"),
 *          @SWG\Property(property="coupon_expire", type="integer", format="int32",  description="拼团等待时间(单位秒,默认10分钟)"),
 *          @SWG\Property(property="coupon_bot_rate", type="string", format="string",  description="机器人参与评团时的胜率(单位:%,默认30%)"),
 *          @SWG\Property(property="alibaba_price", type="string", format="string",  description="商品售价(默认300%)"),
 *          @SWG\Property(property="rebate_rate", type="string", format="string",  description="拼团失败用户的返利比例(单位:%,默认40%)"),
 *          @SWG\Property(property="parent_rate", type="string", format="string",  description="拼团失败会员的上级所得金豆比例"),
 *          @SWG\Property(property="sub_rate", type="string", format="string",  description="拼团失败会员的上上级所得金豆比例"),
 *          @SWG\Property(property="tbk_rebate_rate", type="string", format="string",  description="晒单会员获得金豆数"),
 *          @SWG\Property(property="tbk_parent_rate", type="string", format="string",  description="晒单会员上级所得金豆比例"),
 *          @SWG\Property(property="tbk_sub_rate", type="string", format="string",  description="晒单会员上上级所得金豆比例"),
 *          @SWG\Property(property="title", type="string", format="string",  description="网站标题"),
 *          @SWG\Property(property="title_suffix", type="string", format="string",  description="网站标题后缀"),
 *          @SWG\Property(property="keywords", type="string", format="string",  description="关键词"),
 *          @SWG\Property(property="description", type="string", format="string",  description="描述"),
 *          @SWG\Property(property="price_score_rules", type="string", format="string",  description="价格评分规则"),
 *          @SWG\Property(property="sales_score_rules", type="string", format="string",  description="1688销量评分规则"),
 *          @SWG\Property(property="sales_in_30_days_score_rules", type="string", format="string",  description="平台30天销量评分规则"),
 *          @SWG\Property(property="favour_score_rules", type="string", format="string",  description="收藏评分规则"),
 *          @SWG\Property(property="click_score_rules", type="string", format="string",  description="曝光量/点击量评分规则"),
 *          @SWG\Property(property="order_score_rules", type="string", format="string",  description="点击量/下单量评分规则"),
 *          @SWG\Property(property="download_iOS", type="string", format="string",  description="iOS下载地址"),
 *          @SWG\Property(property="download_Android", type="string", format="string",  description="安卓下载地址"),
 *          @SWG\Property(property="about_us", type="string", format="string",  description="关于我们url"),
 *          @SWG\Property(property="coupon_protocol", type="string", format="string",  description="拼团协议url"),
 *          @SWG\Property(property="refund_protocol", type="string", format="string",  description="退款协议url"),
 *          @SWG\Property(property="return_protocol", type="string", format="string",  description="退货协议url"),
 *          @SWG\Property(property="customer_service", type="string", format="string",  description="客服链接"),
 *          @SWG\Property(property="customer_qq", type="string", format="string",  description="客服qq"),
 *          @SWG\Property(property="customer_wechat", type="string", format="string",  description="客服微信"),
 *          @SWG\Property(property="advance", type="string", format="string",  description="建议url"),
 *          @SWG\Property(property="help", type="string", format="string",  description="帮助的url"),
 *          @SWG\Property(property="record", type="string", format="string",  description="icp备案信息"),
 *          @SWG\Property(property="order_info", type="string", format="string",  description="订单说明url"),
 *          @SWG\Property(property="service_rate", type="string", format="string",  description="退款服务费(单位:%,默认20%)"),
 *          @SWG\Property(property="registration_agreement", type="string", format="string",  description="注册协议"),
 *          @SWG\Property(property="cmc_terms_agreement", type="string", format="string",  description="中国移动认证条款协议的url"),
 *          @SWG\Property(property="coupon_introduction", type="string", format="string",  description="拼团说明"),
 *          @SWG\Property(property="integral_introduction", type="string", format="string",  description="金豆兑换说明"),
 *          @SWG\Property(property="legal_notice", type="string", format="string",  description="法律声明"),
 *          @SWG\Property(property="privacy_agreement", type="string", format="string",  description="隐私协议"),
 *          @SWG\Property(property="coupon_delay", type="integer", format="int32",  description="向1688支付的等待时间(单位:秒,默认600)"),
 *          @SWG\Property(property="userwin", type="integer", format="int32",  description="新用户首次拼单是否失败  1 是  0否"),
 *          @SWG\Property(property="userback", type="string", format="string",  description="新用户首次拼单返现余额"),
 *     )
 * )
 */
class SystemModel extends BaseModel{
    /** 
     * 主键
     */
    public $id = null;

    /** 
     * 基础运费(单位:元,默认:6)
     */
    public $default_post_fee = null;

    /** 
     * 兑换商品所需的积分与商品价格的比例(单位%,默认1000%)
     */
    public $exchange_rate = null;

    /** 
     * 拼团等待时间(单位秒,默认10分钟)
     */
    public $coupon_expire = null;

    /** 
     * 机器人参与评团时的胜率(单位:%,默认30%)
     */
    public $coupon_bot_rate = null;

    /** 
     * 商品售价(默认300%)
     */
    public $alibaba_price = null;

    /** 
     * 拼团失败用户的返利比例(单位:%,默认40%)
     */
    public $rebate_rate = null;

    /** 
     * 拼团失败会员的上级所得金豆比例
     */
    public $parent_rate = null;

    /** 
     * 拼团失败会员的上上级所得金豆比例
     */
    public $sub_rate = null;

    /** 
     * 晒单会员获得金豆数
     */
    public $tbk_rebate_rate = null;

    /** 
     * 晒单会员上级所得金豆比例
     */
    public $tbk_parent_rate = null;

    /** 
     * 晒单会员上上级所得金豆比例
     */
    public $tbk_sub_rate = null;

    /** 
     * 网站标题
     */
    public $title = null;

    /** 
     * 网站标题后缀
     */
    public $title_suffix = null;

    /** 
     * 关键词
     */
    public $keywords = null;

    /** 
     * 描述
     */
    public $description = null;

    /** 
     * 价格评分规则
     */
    public $price_score_rules = null;

    /** 
     * 1688销量评分规则
     */
    public $sales_score_rules = null;

    /** 
     * 平台30天销量评分规则
     */
    public $sales_in_30_days_score_rules = null;

    /** 
     * 收藏评分规则
     */
    public $favour_score_rules = null;

    /** 
     * 曝光量/点击量评分规则
     */
    public $click_score_rules = null;

    /** 
     * 点击量/下单量评分规则
     */
    public $order_score_rules = null;

    /** 
     * iOS下载地址
     */
    public $download_iOS = null;

    /** 
     * 安卓下载地址
     */
    public $download_Android = null;

    /** 
     * 关于我们url
     */
    public $about_us = null;

    /** 
     * 拼团协议url
     */
    public $coupon_protocol = null;

    /** 
     * 退款协议url
     */
    public $refund_protocol = null;

    /** 
     * 退货协议url
     */
    public $return_protocol = null;

    /** 
     * 客服链接
     */
    public $customer_service = null;

    /** 
     * 客服qq
     */
    public $customer_qq = null;

    /** 
     * 客服微信
     */
    public $customer_wechat = null;

    /** 
     * 建议url
     */
    public $advance = null;

    /** 
     * 帮助的url
     */
    public $help = null;

    /** 
     * icp备案信息
     */
    public $record = null;

    /** 
     * 订单说明url
     */
    public $order_info = null;

    /** 
     * 退款服务费(单位:%,默认20%)
     */
    public $service_rate = null;

    /** 
     * 注册协议
     */
    public $registration_agreement = null;

    /** 
     * 中国移动认证条款协议的url
     */
    public $cmc_terms_agreement = null;

    /** 
     * 拼团说明
     */
    public $coupon_introduction = null;

    /** 
     * 金豆兑换说明
     */
    public $integral_introduction = null;

    /** 
     * 法律声明
     */
    public $legal_notice = null;

    /** 
     * 隐私协议
     */
    public $privacy_agreement = null;

    /** 
     * 向1688支付的等待时间(单位:秒,默认600)
     */
    public $coupon_delay = null;

    /** 
     * 新用户首次拼单是否失败  1 是  0否
     */
    public $userwin = null;

    /** 
     * 新用户首次拼单返现余额
     */
    public $userback = null;
    /** 
     * DAO对象
     */
    public $obj = '';

    /** 
     * DAO对象数组
     */
    public $data = [];

    /** 
     * 翻页对象
     */
    public $meta = null;

    /** 
     * 当前页
     */
    public $page = 1;

    /** 
     * 每页显示条数
     */
    public $page_size = 10;

    /** 
     * 主键数组
     */
    public $primary_key_arr = ["id"];

    /** 
     * 自增字段数组
     */
    public $auto_increment_key_arr = ["id"];

    /** 
     * 唯一字段
     */
    public $unique_key_arr = '';

    /** 
     * 单例实例
     */
    static public $instance = null;

    /**
     * @return SystemModel|null
     * @throws ModelSqlException
     */
    static public function getInstance() {
        if(is_null(self::$instance)){
            self::$instance = new self();
        }
        return self::$instance;
    }

    /**
     * SystemModel constructor.
     * @throws ModelSqlException
     */
    public function __construct() {
        parent::__construct(str_replace("Model", "", substr(get_class($this), strrpos(get_class($this), "\\")+1)));
        $this->meta = new \stdClass();
    }

    /**
     * @throws ModelException
     */
    public function __clone() {
        throw new ModelException(
            str_replace('%s', get_class($this), ModelException::INSTANCE_NOT_ALLOW_TO_CLONE), ModelException::INSTANCE_NOT_ALLOW_TO_CLONE_NO);
    }

    public function __destruct() {
        self::$instance = null;
    }

    /**
     * set属性
     *
     * __set. 
     * @param string $name 参数名
     * @param string $value 参数值
     * @return $this
     */
    public function __set($name = "", $value = "") {
        $this->$name = $value;
        return $this;
    }

    /**
     * get属性
     *
     * __get. 
     * @param string $name 参数名
     * @return mixed
     */
    public function __get($name = "") {
        return  $this->$name ;
    }

    /**
     * 创建systemModel
     * 
     * @return mixed
     * @throws ModelDriverException
     * @throws ModelReflectionException
     * @throws ModelSqlException
     * @throws ModelException
     */
    public function insert() {
        return $this->insertRecord();
    }

    /**
     * 编辑systemModel
     * 
     * @return mixed
     * @throws ModelDriverException
     * @throws ModelReflectionException
     * @throws ModelSqlException
     * @throws ModelException
     */
    public function update() {
        return $this->updateRecord();
    }

    /**
     * 删除systemModel，需先指定主键
     * 
     * @return mixed
     * @throws ModelDriverException
     * @throws ModelReflectionException
     * @throws ModelSqlException
     * @throws ModelException
     */
    public function delete() {
        return $this->deleteRecord();
    }

    /**
     * 根据主键查询systemModel，获取单条记录
     *
     * find. 
     * @param int $primary_key 主键编号
     * @return $this
     * @throws ModelException
     * @throws ModelReflectionException
     */
    public function find($primary_key = 0) {
        $result = $this->findByPrimaryKey($primary_key);

        $this->setModelProperty($result);

        return $this;
    }

    /**
     * 根据条件数组查询systemModel，获取多条记录
     *
     * findOneBy. 
     * @param array $condition 查询条件
     * @return $this
     * @throws ModelDriverException
     * @throws ModelException
     * @throws ModelReflectionException
     * @throws ModelSqlException
     */
    public function findOneBy($condition = []) {
        $result = $this->findRecordBy($condition);

        $this->setModelProperty($result);

        return $this;
    }

    /**
     * 根据条件数组查询systemModel，获取多条记录
     *
     * findBy. 
     * @param array $condition 查询条件
     * @return $this
     * @throws ModelDriverException
     * @throws ModelException
     * @throws ModelReflectionException
     * @throws ModelSqlException
     */
    public function findBy($condition = []) {
        $count = $this->getCount($condition);
        $total = $count->fetchColumn();

        $this->data = [];
        $syst_obj = $this->findRecordBy($condition, $this->page, $this->page_size);

        $this->genMeta($total);
        $this->setModelProperty($syst_obj, true);

        return $this;
    }

    /**
     * 批量插入systemModel
     * 
     * @return mixed
     * @throws ModelDriverException
     * @throws ModelException
     * @throws ModelSqlException
     */
    public function batchInsert() {
        return $this->batchInsertRecord();
    }

    /**
     * 批量删除systemModel
     * 
     * @throws ModelDriverException
     * @throws ModelException
     * @throws ModelSqlException
     */
    public function batchDelete() {
        $this->batchDeleteRecord();
    }

    /**
     * 生成批量生成update的sql
     * 
     * @return bool|string
     * @throws ModelDriverException
     * @throws ModelException
     * @throws ModelSqlException
     */
    public function genBatchUpdateSql() {
        return $this->_genBatchUpdateSql();
    }

}